package com.xk.school_device.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.xk.school_device.common.Result;
import com.xk.school_device.entity.Devices;
import com.xk.school_device.service.IDevicesService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xk
 * @since 2025-04-16
 */
@RestController
@RequestMapping("/devices")
public class DevicesController {

    private IDevicesService devicesService;
    /**
     * 设备登记
     */
    @PostMapping("/register")
    public Result register(Devices devices) {
         devicesService.save(devices);
        return Result.success("设备登记成功");
    }
    /**
     * 设备查询
     */
    @PostMapping("/query")
    public Result query(Devices devices) {
        QueryWrapper<Devices> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("devices_id",devices.getDeviceId())
                .like("devices_name",devices.getDeviceName())
        .like("model",devices.getModel())
        .like("category",devices.getCategory())
        .like("brand",devices.getBrand())
                .like("serial_number", devices.getSerialNumber())
        ;
        List<Devices> devices1 = devicesService.getBaseMapper().selectList(queryWrapper);
        return Result.success("设备查询成功",devices1);
    }
    /**
     * 设备更新
     */
    @PostMapping("/update")
    public Result update(Devices devices) {
        devicesService.updateById(devices);
        return Result.success("设备更新成功");
    }

    /**
     * 设备删除
     */
    @PostMapping("/delete")
    public Result delete(Devices devices) {
        devicesService.removeById(devices);
        return Result.success("设备删除成功");
    }
}
